package com.jijuxie.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jijuxie.system.domain.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {

    /**
     * 通过用户名查询用户
     */
    SysUser selectUserByUsername(@Param("username") String username);

    /**
     * 通过用户ID查询用户
     */
    SysUser selectUserById(@Param("userId") Long userId);

    @Select("SELECT COUNT(1) FROM sys_user WHERE username = #{username} AND del_flag = '0'")
    int selectCountByUsername(String username);
    
    @Select("SELECT COUNT(1) FROM sys_user WHERE phone_number = #{phone} AND del_flag = '0'")
    int selectCountByPhone(String phone);
    
    @Select("SELECT COUNT(1) FROM sys_user WHERE email = #{email} AND del_flag = '0'")
    int selectCountByEmail(String email);

    /**
     * 根据用户名查询用户
     */
    SysUser selectByUsername(@Param("username") String username);
    
    /**
     * 根据手机号查询用户
     */
    @Select("SELECT * FROM sys_user WHERE phone_number = #{phone} AND del_flag = '0'")
    SysUser selectByPhone(@Param("phone") String phone);
    
    /**
     * 根据邮箱查询用户
     */
    SysUser selectByEmail(@Param("email") String email);
}
